#!/usr/bin/env python
# encoding: utf-8
"""
axfr.py

Created by Stefan Schmidt on 2009-08-09.
Copyright (c) 2009 __MyCompanyName__. All rights reserved.
"""

import sys
import os
import dns.query
import dns.zone
import dns.rdatatype
import dns.resolver
import dns.query
import dns.zone
from dns.exception import DNSException
from dns.rdataclass import *
from dns.rdatatype import *

domain = "visitors.har2009.net"
n="87.76.11.14"
print "Getting NS records for", domain
answers = dns.resolver.query(domain, 'NS')
print "\nTrying a zone transfer for %s from name server %s" % (domain, n)
try:
	zone = dns.zone.from_xfr(dns.query.xfr(n, domain))
except DNSException, e:
	print e.__class__, e
for name, node in zone.nodes.items():
	rdatasets = node.rdatasets
	for rdataset in rdatasets:
		if rdataset.rdclass == IN and rdataset.rdtype is A:
			print name
			print " " + str(rdataset[0]) + ""
